module wait_fork_process;

task automatic print_value(input int tid, input int value, input int delay);
    begin
        #(delay) $display("@%0t [%0d]: Value=%0d\tDelay=%0d", $time, tid, value, delay);
    end
endtask

initial begin
    fork
        #1 print_value(1, 10, 7);
        #1 print_value(2, 8, 5);
        #1 print_value(3, 4, 2);
    join_none
    #5 ;
    fork
        #1 print_value(4, 1, 1);
        #1 print_value(5, 2, 2);
        #1 print_value(6, 3, 3);
    join_any
    $display("@%g\tCame out of fork-join", $time);
    //执行到此,  wait-fork 会等待所有的线程完成才会继续执行后续代码
    // wait for all threads to complete
    wait fork;
    $display("@%g\tAll threads are completed", $time);
    #20 $finish;
end

endmodule // wait_fork
